package com.guigu.buy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.buy.dto.Out_Detail;
import com.guigu.buy.dto.Storage_Stock;
import com.guigu.buy.pojo.Order;
import com.guigu.buy.pojo.OutGather;
import com.guigu.buy.mapper.OutGatherMapper;
import com.guigu.buy.service.IOrderService;
import com.guigu.buy.service.IOutDetailsService;
import com.guigu.buy.service.IOutGatherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.buy.vo.OutVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author com.guigu
 * @since 2024-05-15
 */
@Service
public class OutGatherServiceImpl extends ServiceImpl<OutGatherMapper, OutGather> implements IOutGatherService {
        @Autowired
        private OutGatherMapper outGatherMapper;
        @Autowired
        private IOutDetailsService outDetailsService;
        @Autowired
        private IOrderService orderService;
    @Override
    public String getMaxDesignId() {
        OutGather outGather=outGatherMapper.queryMax();
        if(outGather==null){
            return null;
        }
        String designId=outGather.getOutId();
        return designId;
    }

    @Override
    public String add(Out_Detail out_detail, int id) {
        out_detail.setId(null);
        out_detail.setStockId(id);
        boolean s=this.save(out_detail);
        if(s){
            outDetailsService.add(out_detail.getList());
            Order order=new Order();
            order.setId(id);
            order.setConveyTag("P001-2");
            orderService.updateById(order);
            return "ok";
        }
        return "no";
    }

    @Override
    public PageInfo<Out_Detail> queryAll(int pageNo, int pageSize, OutVo vo) {
        List<Out_Detail> list=outGatherMapper.queryAll(vo);
        PageHelper.startPage(pageSize,pageNo );
        PageInfo<Out_Detail> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }
}
